#include "Constant.h"
#include "Entity.h"
#include "EntityGenerator.h"
#include "Vector3.hpp"
#include "time.h"
#include "mt.h"
using namespace std;

EntityGenerator::EntityGenerator()
{	
	rangeForces = new float*[3];
	rangePosition = new float*[3];
	
	

	for (int i=0; i<3; i++)
	{
		rangeForces[i] = new float[2];
		rangeForces[i][0] = 0;
		rangeForces[i][1] = 0;

		rangePosition[i] = new float[2];
		rangePosition[i][0] = 0;
		rangePosition[i][1] = 0;
	}
}

EntityGenerator::~EntityGenerator()
{	}

void EntityGenerator::Generate(map<int, Entity*> &entityList, int numberOfElements)
{
	//Generate a specific number of particles by definied rules
	Entity* tmp;
	int idOffset = entityList.size();
	

	
	 
	for (int i=0; i < numberOfElements; i++)
	{
		tmp = new Entity(	defaultMass, 
							new Vector3(	rangePosition[0][0] + (rangePosition[0][1] * rand() / ( RAND_MAX + 1.0f)), 
											rangePosition[1][0] + (rangePosition[1][1] * rand() / ( RAND_MAX + 1.0f)),
											rangePosition[2][0] + (rangePosition[2][1] * rand() / ( RAND_MAX + 1.0f))),
							new Vector3(	RandomFloatX(), RandomFloatY(), 0));
		entityList.insert(pair<int, Entity*>(idOffset + i, tmp));
	}
}




void EntityGenerator::SetDefaultMass(float mass)
{
	if(mass > 0)
	{
		defaultMass = mass;
	}
	else
	{
		defaultMass = 1;
	}
}

//Define the range of entities forces for the random generator
void EntityGenerator::SetRangeForce(Axis axis, float min, float max)
{
	rangeForces[axis][0] = min;
	rangeForces[axis][1] = max;
}

//Define the range of entities position for the random generator
void EntityGenerator::SetRangePosition(Axis axis, float min, float max)
{
	rangePosition[axis][0] = min;
	rangePosition[axis][1] = max;
}